home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr40 / radserv.zip / UTIL.C < prev   
C/C++ Source or Header  |  1994-11-15  |  2KB  |  108 lines

  1.  
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. void
  8. UpperCase(cp)
  9. char *cp;
  10. {
  11.     for (; cp && *cp; cp++)
  12.         if (islower(*cp))
  13.             *cp = toupper(*cp);
  14. }
  15.  
  16.  
  17. char *
  18. stripLeadingSpace(cp)
  19. char *cp;
  20. {
  21.     while (cp && *cp && (*cp == ' ' || *cp == '\t' || *cp == '\n'))
  22.         cp++;
  23.     return cp;
  24. }
  25.  
  26. void
  27. stripTrailingSpace(s)
  28. char *s;
  29. {
  30.     register char *t;
  31.  
  32.     if (!s)
  33.         return;
  34.  
  35.     t = s + strlen(s) - 1;
  36.     while ((t >= s) && ((*t == ' ') || (*t == '\t') || (*t == '\n')))
  37.         t--;
  38.     t++;
  39.     *(t) = '\0';
  40. }
  41.  
  42. /*
  43.  * Save a string in alloc'd memmory.
  44.  */
  45. char *
  46. saveString(s)
  47. char *s;
  48. {   
  49.     char *t;
  50.     HANDLE hgp;
  51.  
  52.     hgp =  GlobalAlloc(GPTR, strlen(s)+1);
  53.     if (hgp == NULL)
  54.         return NULL;
  55.     t = GlobalLock(hgp);
  56.     strcpy(t, s);
  57.     GlobalUnlock(hgp);
  58.     return t;
  59. }
  60.  
  61. /*
  62.  * Allocate memory with error checking.
  63.  */
  64.  
  65.  
  66. char *
  67. getline(buf, size, fp)
  68. char *buf;
  69. int size;
  70. FILE *fp;
  71. {
  72.     char lbuf[200];
  73.     char *cp;
  74.  
  75.     if (!fp)
  76.         return NULL;
  77.  
  78.     if (fgets(lbuf, sizeof(lbuf), fp) == NULL)
  79.         return NULL;
  80.     if (feof(fp))
  81.         return NULL;
  82.     cp = stripLeadingSpace(lbuf);
  83.     strncpy(buf, lbuf, size);
  84.     stripTrailingSpace(buf);
  85.  
  86.     return buf;
  87. }
  88.  
  89.  
  90. int
  91. cistrcmp(src,dst)
  92. char *src,*dst;
  93. {
  94.     char d[64],s[64];
  95.     register int i;
  96.  
  97.     for (i=0; i<64 && *src; src++,i++)
  98.         if (isupper(s[i] = *src))
  99.             s[i] = tolower(s[i]);
  100.     s[i] = 0;
  101.     for (i=0; i<64 && *dst; dst++,i++)
  102.         if (isupper(d[i] = *dst))
  103.             d[i] = tolower(d[i]);
  104.     d[i] = 0;
  105.     return strcmp(s,d);
  106. }
  107.  
  108.